package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wechat.domain.WxScenicSpots;
import com.ruoyi.wechat.service.IWxScenicSpotsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>ClassName : WxScenicSpotsController</p>
 * <p>Description : </p>
 *
 * @author 孙伟光
 * @version 1.0
 * @date 2024/7/26 16:29
 */
@Api(value = "微信小程序API-营地周边景点管理", tags = {"微信小程序API-营地周边景点管理"})
@RestController
@RequestMapping("/wechat/spots")
public class WxScenicSpotsController extends BaseController {

    @Autowired
    private IWxScenicSpotsService wxScenicSpotsService;

    @ApiOperation(value = "根据营地Id获取该营地下的周边景点列表", response = WxScenicSpots.class)
    @GetMapping("/getInfoByCampId/{campId}")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "campId", value = "营地Id", required = true, dataType = "String", paramType = "query"),
//    })
    public AjaxResult getInfoByCampId(@PathVariable("campId") String campId) {
        if (campId == null) {
            return error("营地Id不能为空");
        }
        List<WxScenicSpots> list = wxScenicSpotsService.getInfoByCampId(campId);
        return success(list);
    }

    @ApiOperation(value = "根据周边景点Id查询详细信息", response = WxScenicSpots.class)
    @GetMapping("/getInfoByScenicId/{scenicId}")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "scenicId", value = "周边景点Id", required = true, dataType = "String", paramType = "query"),
//    })
    public AjaxResult getInfoByScenicId(@PathVariable("scenicId") String scenicId) {
        if (scenicId == null) {
            return error("周边景点Id不能为空");
        }
        WxScenicSpots wxScenicSpots = wxScenicSpotsService.getInfo(scenicId);
        return success(wxScenicSpots);
    }

    @ApiOperation(value = "添加周边景点并提交审批")
    @Log(title = "微信小程序API-营地周边景点管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WxScenicSpots wxScenicSpots){
        if (wxScenicSpots == null) {
            return error("数据不能为空");
        }
        if (wxScenicSpots.getCampId() == null) {
            return error("营地Id不能为空");
        }
        if (wxScenicSpots.getScenicName() == null) {
            return error("景点名称不能为空");
        }
        if (wxScenicSpots.getLatitude() == null || wxScenicSpots.getLongitude() == null) {
            return error("经纬度不能为空");
        }
        return toAjax(wxScenicSpotsService.insertScenicSpots(wxScenicSpots));
    }

    @ApiOperation(value = "修改周边景点并提交审批")
    @Log(title = "微信小程序API-营地周边景点管理", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult update(@RequestBody WxScenicSpots wxScenicSpots) {
        if (wxScenicSpots == null) {
            return error("数据不能为空");
        }
        if (wxScenicSpots.getScenicId() == null) {
            return error("营地景点Id不能为空");
        }
        if (wxScenicSpots.getCampId() == null) {
            return error("营地Id不能为空");
        }
        if (wxScenicSpots.getScenicName() == null) {
            return error("景点名称不能为空");
        }
        if (wxScenicSpots.getLatitude() == null || wxScenicSpots.getLongitude() == null) {
            return error("经纬度不能为空");
        }
        return toAjax(wxScenicSpotsService.updateScenicSpots(wxScenicSpots));
    }

    @ApiOperation(value = "根据周边景点Id完成删除")
    @Log(title = "微信小程序API-营地周边景点管理", businessType = BusinessType.DELETE)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "scenicId", value = "周边景点Id", required = true, dataType = "String", paramType = "query"),
//    })
    @DeleteMapping("/delete/{scenicId}")
    public AjaxResult delete(@PathVariable("scenicId") String scenicId){
        if (scenicId == null) {
            return error("周边景点Id不能为空");
        }
        return toAjax(wxScenicSpotsService.deleteScenicSpotsByScenicId(scenicId));
    }

    @ApiOperation(value = "审批")
    @Log(title = "微信小程序API-营地周边景点管理", businessType = BusinessType.GRANT)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scenicId", value = "周边景点Id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "approve", value = "审批状态", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "content", value = "意见", required = true, dataType = "String", paramType = "query"),
    })
    @PutMapping("/approve")
    public AjaxResult approve(@RequestBody WxScenicSpots wxScenicSpots) {
        return toAjax(wxScenicSpotsService.approve(wxScenicSpots.getScenicId(),wxScenicSpots.getApprove(),wxScenicSpots.getContent()));
    }
}
